home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl
- #
- # inst-get -- inspired by all the requests for Debian "apt-get" functionality
- # in IRIX's inst. This is a crude implementation, as it is
- # just a wrapper around "wget" and "inst". Since inst has
- # slow startup and shutdown, this script can be very slow,
- # in addition to how slow downloading the packages is over
- # your internet connection.
- #
- # Usage:
- # inst-get [-v] [-d <dir>] package [package ...]
- # "-v" sets wget to be verbose.
- # "-d <dir>" uses a non-default directory
- # "package" is a (usually) unique name part to get
- #
- # Author:
- # Scott Henry <scotth@sgi.com>, 2001-05-08
- #
- # License: What the heck:
- # (C) Copyright 2001-2002 Scott Henry and Silicon Graphics, Inc
- # This program is distributed under the GNU Public License,
- # version 2. There is no warranty on this software, use at
- # your own risk.
- #
- # History:
- # 0.1 (2001-05-08) first version, does downloads only.
- # It doesn't know about "or" dependencies, and
- # downloads all of them...
-
- use Getopt::Std;
- #
- # Some sites (like here) may need to use SOCKS to get out to the Internet
- # Uncomment and modify as needed
- #
- # $ENV{"SOCKS_SERVER"} = "";
- # $ENV{"SOCKS_NS"} = "";
- $SOCKS = ""; # pmsocks or whatever
-
- getopts("vd:") or die "Usage: $0 [-v] [-d dir] package [package ...]\n";
-
- $FW_URL = "http://freeware.sgi.com/Dist";
- $WGET = "/usr/freeware/bin/wget";
- $WG_OPTS = "-q";
- if ($opt_v) {
- $WG_OPTS = "";
- }
- $DIST_DIR = $opt_d ? $opt_d : "/var/tmp/inst-get";
- -d $DIST_DIR or mkdir $DIST_DIR,0775 or die "Can't mkdir $DIST_DIR? $?\n";
-
- chdir $DIST_DIR or die "Can't cd to $DIST_DIR? $?\n";
-
- @pkgs = @ARGV; # initial packages to download
- unless (@pkgs) {
- die "Nothing to fetch? no packages on command line\n";
- }
-
- # grab the directory listing of the freeware site.
- # also makes sure that we can access it.
- if ($SOCKS) {
- system($SOCKS, $WGET, $WG_OPTS, $FW_URL."/.");
- } else {
- system($WGET, $WG_OPTS, $FW_URL."/.");
- }
-
- # parse the package tardist names from the downloaded index file.
- @packages = ();
- open(R, "<index.html") or die "Failed to download index.html from $FW_URL?\n";
- while(<R>) {
- next unless /HREF=\"([^\/\"]+)\"/;
- push @packages, $1;
- }
- close(R);
-
- # setup the inst stuff
- $CMDFILE = "cmd.file";
- open(C, ">$CMDFILE") or die "Can't create inst command file? $?\n";
- print C "install prereqs\nconflicts\nkeep *\nquit\n";
- close(C);
- $INSTCMD = "/usr/sbin/inst -E -M -f . -c $CMDFILE -I default";
-
- $downloaded = 0;
- # now loop while we have packages to fetch.
- while ($#pkgs >= 0) {
- @fetch = (); # clear it out
- # convert package name to tardist file
- foreach $p (@pkgs) {
- push(@fetch, grep(/$p/, @packages));
- }
- if ($#fetch < 0) {
- die "no packages found to download\nMisspelled package names or broken dependencies?\n";
- }
- # download each tardist file in turn
- foreach $p (@fetch) {
- if (-f $p) {
- print "$p already downloaded\n";
- } else {
- print "downloading $p ...";
- system($SOCKS, $WGET, $WG_OPTS, $FW_URL."/".$p);
- system("/usr/bin/tar", "-xf", $p);
- $downloaded++;
- print "\n";
- }
- }
- # now run inst on the files
- @pkgs = ();
- open(I, "$INSTCMD |");
- while(<I>) {
- last if /^No conflicts/;
- next unless /Also install\s+([-_\w]+)\.[-_\w]+\.[-_\w]+\s/;
- push @pkgs, $1;
- while(<I>) {
- last unless /\s([-_\w]+)\.[-_\w]+\.[-_\w]+\s/;
- push @pkgs, $1;
- }
- }
- close(I);
- }
- print "$downloaded packages fetched\n";
-